package com.lwc.controller;

import com.lwc.bean.User;
import com.lwc.bean.newUser;
import com.lwc.common.bean.ResultBean;
import com.lwc.common.controller.BaseController;
import com.lwc.mapper.UserMapper;
import com.lwc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户管理")
@RequestMapping("/api")

public class UserController extends BaseController {

    @Autowired
    UserService userService;
@Autowired
    UserMapper userMapper;

    @ApiOperation("注册")
    @PostMapping("zuce")
    public ResultBean get(newUser newUser){
int rs= userService.save(newUser);
return rs==1?success("注册成功"):fail("注册失败");
    }

    @ApiOperation("登录")
    @GetMapping("/denglu")
    public ResultBean denglu(String username,String password){
User user=userService.query(username,password);
      String lastTime=userService.query(username,password).getLastLoginTime();
int rs =userMapper.updatelastLonginTime(user.getId());
    return rs==1?success("登陆成功",lastTime):fail("登录失败");
    }


    @ApiOperation("修改密码")
    @PutMapping("/update")
    public  ResultBean updatepassword(int id,String password){
int rs=userService.uodatepassword(id, password);
        return rs==1?success("更改成功"):fail("更改失败");
    }




}
